package admin

import (
	"exercise/application/yiran/app/libs"
	"exercise/application/yiran/app/request/adminRequest"
	"exercise/application/yiran/app/service/admin"
	"github.com/gin-gonic/gin"
)

type roomSeatController struct{}

func (*roomSeatController) List(ctx *gin.Context) {
	request := new(adminRequest.RoomSeatListRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewRoomSeatService().List(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*roomSeatController) Add(ctx *gin.Context) {
	request := new(adminRequest.AddRoomSeatRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewRoomSeatService().Add(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*roomSeatController) Edit(ctx *gin.Context) {
	request := new(adminRequest.EditRoomSeatRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewRoomSeatService().Edit(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "编辑成功")
}

func (*roomSeatController) Detail(ctx *gin.Context) {
	ret, err := admin.NewRoomSeatService().Detail(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*roomSeatController) Deleted(ctx *gin.Context) {
	err := admin.NewRoomSeatService().Deleted(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "删除成功")
}

// InitRoom 初始化房间
func (r *roomSeatController) InitRoom(ctx *gin.Context) {
	request := new(adminRequest.InitRoomRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewRoomSeatService().InitRoom(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "初始化成功")
}

// ResetRoom 重置房间容量
func (r *roomSeatController) ResetRoom(ctx *gin.Context) {
	request := new(adminRequest.ResetRoomRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewRoomSeatService().ResetRoom(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "重置房间成功")
}

func NewRoomSeatController() *roomSeatController {
	return &roomSeatController{}
}
